package StackPractice;

import java.util.LinkedList;
import java.util.Queue;

class MyStack {
    LinkedList<Integer> queue1 = null;
    LinkedList<Integer> queue2 = null;

    public MyStack() {
        queue1 = new LinkedList<>();
    }

    public void push(int x) {
        queue2 = new LinkedList<>();
        queue2.add(x);
        while (!queue1.isEmpty()) {
            queue2.add(queue1.pop());
        }
        queue1 = queue2;
    }

    public int pop() {
        return queue1.pop();
    }

    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }

    public static void main(String[] args) {
        MyStack queue = new MyStack();
        queue.push(1);
        queue.push(2);
        queue.push(3);
        System.out.println(queue.pop());
        System.out.println(queue.pop());
        System.out.println(queue.pop());

    }
}